package com.bang.study.scheduled;

import com.bang.study.constants.PublicConstants;
import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyContext;
import org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus;
import org.apache.rocketmq.client.consumer.listener.MessageListenerConcurrently;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.common.message.MessageExt;

import java.util.List;

/**
 * @ClassName: ScheduledMessageConsumer
 * @Desc: TODO
 * @Auther: <Bang>
 * @Date: 2020/05/06 20:23
 * @Version: 1.0
 * @Modified By:
 */
public class ScheduledMessageProducer {

    public static void main(String[] args) throws Exception{
        DefaultMQProducer producer = new DefaultMQProducer(PublicConstants.TEST_PRODUCER_GROUP);
        producer.setNamesrvAddr(PublicConstants.NAME_ADDR);
        producer.start();
        int totalMessagesToSend = 6;
        for (int i = 0; i < totalMessagesToSend; i++) {
            Message message = new Message("Scheduled_Topic", ("Hello scheduled message " + i).getBytes());
            // This message will be delivered to consumer 10 seconds later.
            message.setDelayTimeLevel(3);
            // Send the message
            producer.send(message);
        }

        // Shutdown producer after use.
        System.out.println("发送完毕");
        producer.shutdown();
    }
}
